/* --------------------------------------
SUMMARY: 	- Estimating discete choice models
			- Exporting the estimated parameters to a new dataset
AUTHOR: Thimo De Schouwer (KU LEUVEN)
NOTES: 		- Preference / WTP coefficients vary over wage distribution
DATE CREATED: 16/09/2021
STATA VERSION: MP 17.0
--------------------------------------- */

clear all
drop _all

cd "${dir}\DataCode\Data\Constructed\LISS"
use Clean_LISS_Preferences.dta , clear
	
*** Part 0 - DEMOGRAPHICS and AMENITIES by GENDER
** Section 0.1 - DEMOGRAPHICS
* Generating means / sd by gender (of binary variables)
foreach i in married leeftijd child high_flex high_telecommute high_meaning education{
	summ `i'
	gl mean_`i'0 	= r(mean)
	gl sd_`i'0 		= r(sd)
	
	ttest `i', by(woman)
	gl mean_`i'1 	= r(mu_1)
	gl sd_`i'1		= r(sd_2) 
	
	gl mean_`i'2 	= r(mu_2)
	gl sd_`i'2	= r(sd_2)
	
	gl pval_`i' 	= r(p)
	
	* Counts: observations & nr_(wo)men
	gl nr_men = r(N_1)
	gl nr_women = r(N_2)
	summ married, det
	gl nr_tot = r(N)
	
}


* Prepare for latex export
matrix define sum_general = (round($nr_tot, 1), round($nr_men, 1), round($nr_women, 1), . \ ///
							round($mean_leeftijd0, .01), round($mean_leeftijd1, .01), round($mean_leeftijd2, .01), round($pval_leeftijd, .01) \ ///
							round($sd_leeftijd0, .01), round($sd_leeftijd1, .01), round($sd_leeftijd2, .01), . \ ///
							round($mean_married0, .01), round($mean_married1, .01), round($mean_married2, .01), round($pval_married, .01)  \ ///
							round($mean_child0, .01), round($mean_child1, .01), round($mean_child2, .01), round($pval_child, .01)  \ ///
							round($mean_education0, .01), round($mean_education1, .01), round($mean_education2, .01), round($pval_education, .001) \ ///
							round($sd_education0, .01), round($sd_education1, .01), round($sd_education2, .01), . \ ///
							round($mean_high_flex0, .01), round($mean_high_flex1, .01), round($mean_high_flex2, .01), round($pval_flex_d, .01)  \ ///
							round($sd_high_flex0, .01), round($sd_high_flex1, .01), round($sd_high_flex2, .01), . \ ///
							round($mean_high_telecommute0, .01), round($mean_high_telecommute1, .01), round($mean_high_telecommute2, .01), round($pval_high_telecommute, .01)  \ ///
							round($sd_high_telecommute0, .01), round($sd_high_telecommute1, .01), round($sd_high_telecommute2, .01), . \ ///
							round($mean_high_meaning0, .01), round($mean_high_meaning1, .01), round($mean_high_meaning2, .01), round($pval_high_meaning, .01)  \ ///
							round($sd_high_meaning0, .01), round($sd_high_meaning1, .01), round($sd_high_meaning2, .01), . )
 		
mat coln sum_general = "Total" "Men" "Women" "P-value"
mat rown sum_general = "Observations: Number of obs." "Age: Mean" "Age: Std dev" "Family: Married (\%)" "Family: Children (\%)" ///
						"Education: Years of Schooling (mean)" "Education: Years of Schooling (std dev)" ///
						"Amenities: Schedule Adaptability (mean)"  "Amenities: Schedule Adaptability (std dev)" ///
						"Amenities: Telecommuting (mean)" "Amenities: Telecommuting (std dev)" ///
						"Amenities: Meaning (mean)" "Amenities: Meaning (std dev)" 



esttab matrix(sum_general, fmt(2)) using "$dir\GraphsTables\OnlineAppendix\Table_BackgroundStats_LISS.txt", tex varwidth(20) modelwidth(10) ///
    replace nomtitle nogaps nofloat
	
	